<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
     <link rel="stylesheet" href="../../layuimini-2/css/public.css" media="all">
    <link rel="stylesheet" href="../../layuimini-2/lib/layui-v2.5.5/css/layui.css">
    <link rel="stylesheet" href="../../layuimini-2/js/lay-module/dtree/dtree.css">
    <link rel="stylesheet" href="../../layuimini-2/js/lay-module/dtree/font/dtreefont.css">
    <script src="../../layuimini-2/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../../layuimini-2/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
    <script src="../../common/js/getQueryVariable.js"></script>
    <style>
        #dtreeDiv{
            width: 100%;
            background: #ffffff;
            position: absolute;
            z-index: 1;
           display:none;
        }
    </style>
    <script>
        layui.use(["jquery"],function (){
            $=layui.jquery;
       $(function (){
           $.ajax({
          type:"post",
          url:"/admin/menu/getone",
          data:{id:getQueryVariable("id")},
          success:function (json){
               $("#id").val(getQueryVariable("id"));
              $("#pid").val(json.pid);
              //$("#layui-unselect").val(json.p_name);
              $("#title").val(json.title);
              $("#icon").val(json.icon);
              $("#href").val(json.href);
              if(json.target!="_self"){
                  $("#_blank").attr("checked","checked");
              }else{
                  $("#_self").attr("checked","checked");
              }
              $("#sort").val(json.sort);
          },
          error:function (info){
              console.log(info);
          }
      });
        });
        })
    </script>
    <script>
        function dtreeShow(){
            var dtreeDiv=document.getElementById("dtreeDiv");
            var display=dtreeDiv.style.display;
            if (display==="none"){
                dtreeDiv.style.display="block";
            }else if(display==="block"){
                dtreeDiv.style.display="none";
            }else{
                dtreeDiv.style.display="block";
            }
        }
    </script>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
       <!-- <label class="layui-form-label required">上级菜单</label>-->
        <div class="layui-input-block">
            <div class="layui-unselect layui-form-select">
                <div class="layui-select-title">
                    <input type="hidden" id="id" name="id">
                    <input type="hidden" id="pid" name="pid">
                    <input type="hidden" id="action" name="action" value="edit">
                   <!-- <span>
                        <input disabled="disabled" id="layui-unselect" type="text" placeholder="请选择"  class="layui-input layui-unselect">
                    </span>-->
                    <div id="dtreeDiv">
                        <ui  id="selTree1" ></ui>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">菜单名称</label>
        <div class="layui-input-block">
            <input type="text" id="title" name="title" lay-verify="required" lay-reqtext="菜单名不能为空" placeholder="请输入菜单名称" value="" class="layui-input">
            <tip>填写菜单名称。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">图标</label>
        <div class="layui-input-block">
            <input type="text" id="icon" name="icon" lay-verify="required" lay-reqtext="图标属性不能为空" placeholder="请输入图标属性" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单URL</label>
        <div class="layui-input-block">
            <input type="text" id="href" name="href" placeholder="请输入URL" value="" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">target</label>
        <div class="layui-input-block">
           <input type="radio" id="_self" name="target" value="_self" title="_self">
            <input type="radio" id="_blank" name="target" value="_blank" title="_blank">
         </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">排序号</label>
        <div class="layui-input-block">
            <input type="number" id="sort" name="sort" placeholder="请输入数字" class="layui-input" lay-verify="required" lay-reqtext="请输入排序数字">
            <tip>填写排序号</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script>
    layui.use(["jquery",'form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var str=JSON.stringify(data.field);
           $.ajax({
              type:'post',
              url:"/admin/menu/edit",
              data:data.field,
              success:function (res){
                 if (res==="ok"){
                     layer.msg("提交成功");
                    setTimeout(function (){
                        var index=parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    },2000)
                 }else{
                     layer.msg(res);
                 }
              },
              error:function (msg){
                  console.log(msg);
              }
          })
            return false;
        });
    });
</script>
<script type="text/javascript">
    layui.use(["jquery",'element','layer', 'table', 'code' ,'util', 'dtree', 'form'], function(){
        var element = layui.element,
            layer = layui.layer,
            table = layui.table,
            util = layui.util,
            dtree = layui.dtree,
            form = layui.form,
            $=layui.jquery;
        //var data = dtreeData;
        var DTree = dtree.render({
            elem: "#selTree1",
            method:"get",
            width: "100%", // 指定树的宽度
           // data: dtreeData,
            open:false,
            icon: "-1",  // 隐藏二级图标
            skin: "laySimple",  // laySimple主题风格
            url:""
        });
        dtree.on("node(selTree1)",function(obj){
          var str=JSON.stringify(obj.param);
          str=eval("("+str+")");
           $("#layui-unselect").val(str.context);
           $("#pid").val(str.nodeId);
           $("#dtreeDiv").css("display","none");
        })
    });
</script>
</body>
</html>
